<?php

class Shell_Command_UserAdd extends  Shell_Command_Abstract_CommandBase implements Shell_Command_Abstract_IShellCommand{
//*************************************************************************************************
		
		public function __construct() 
		{
			parent::__construct();
			$this->NAME = "useradd";
		}
		
//*************************************************************************************************
		public function execute($arguments) 
		{						
			$userName = "";
			if ( count($arguments)!=0 )
			{
				//$userName = $arguments[ count($arguments)-1 ];
				$userName = $arguments[0];
			}
			
			if ($userName == "")
			{
				$userName = Core_IO::readUserInput("user name: ", true);
			}
			
			$age = Core_IO::readUserInput("user age: ", true);
			$password = Core_IO::readUserInput("password: ", true);
			$email = Core_IO::readUserInput("e-mail: ", true);
			
			$sqlitePath = Core_Registry::read(Enum_RegistryItems::SQLITE_PATH);				
			$adapter = new System_UMS_SQLiteAdapter($sqlitePath);
			$ums = new System_UMS($adapter);

			$user = new System_UMS_User($userName, $password, $age, $email);
			$errorCode = $ums->userAdd($user);
			
			//echo "\n\nerrorCode=$errorCode\n\n";
			
			$positiveMsg = "User $userName was sucessfully added."; 
			$negativeMsg = "There was an error while adding user ".$userName."! Error code:$errorCode";			
			$this->parseErrorCode($errorCode, $positiveMsg, $negativeMsg);
			
		}
		
//*************************************************************************************************		
		public function __toString() {
			return "[UserAdd]";
		}
}


// *****************************************************
// Part #3 - Modifying a line of screen text
// *****************************************************
/*
$counter2 = $counter;
while($counter2 >= 0){
  $output_str =  "Current count is ".$counter2." out of ".$counter.". ";
  echo $output_str;
  $line_size = strlen($output_str);
  while($line_size >= 0){
    echo "\010";
    $line_size--;
  }
  $counter2--;
  sleep(1);
}
*/
// *****************************************************